package com.attcatstudy.cas;

import java.util.concurrent.atomic.AtomicIntegerArray;

/**
 * @author attcat
 * ---做一个有趣的程序员
 * @date 2022-11-02 20:30
 * @description
 */
public class AtomicIntegerArrayTest {
    static int[] value = new int[]{ 1, 2, 3, 4, 5 };
    static AtomicIntegerArray atomicIntegerArray = new AtomicIntegerArray(value);

    public static void main(String[] args) {

        atomicIntegerArray.set(0,100);
        System.out.println(atomicIntegerArray.get(0));
        System.out.println(atomicIntegerArray.get(1));

        ////以原子更新的方式将数组中索引为1的元素与输入值相加;
        atomicIntegerArray.getAndAdd(1,5);

        System.out.println(atomicIntegerArray.get(1));
    }

}
